package com.luguangtao.controller;

import com.luguangtao.dao.InsuranceDao;
import com.luguangtao.dao.TypeDao;
import com.luguangtao.dao.UserDao;
import com.luguangtao.entity.IeType;
import com.luguangtao.entity.Insurance;
import com.luguangtao.entity.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Optional;

/**
 * @类名: com.luguangtao.controller
 * @作者: lgt
 * @创建时间: 2019-12-16 09:12
 * @描述:
 **/
@RestController
@CrossOrigin
public class InsuranceController1 {

    @Autowired
    UserDao userDao;
    @Autowired
    InsuranceDao insuranceDao;
    @Autowired
    TypeDao typeDao;

    //列表+分页+模糊
    @RequestMapping("lists")
    public Page<Insurance> lists(@RequestParam(defaultValue = "1") Integer pageNum, @RequestParam Double am1, @RequestParam Double am2, IeType ieType){
       if(am1!=null && am1!=0){  //判断保险金额区间
           Page<Insurance> all1 = insuranceDao.findByInsuranceamountBetween(PageRequest.of(pageNum-1,3),am1,am2);
            return all1;
       }else if(ieType!=null){
           Page<Insurance> byIeType = insuranceDao.findByIeType(PageRequest.of(pageNum - 1, 3), ieType);
           return byIeType;
       }
       else{
           Page<Insurance> all = insuranceDao.findAll(PageRequest.of(pageNum - 1, 3));
           return all;
       }
    }
}
